package xaj.puiatti.ast;

import java.util.Iterator;
import java.util.List;

import polyglot.ast.Block;
import polyglot.ast.TypeNode;
import polyglot.lex.Identifier;
import polyglot.types.Flags;
import polyglot.util.CodeWriter;
import polyglot.util.Position;
import polyglot.visit.PrettyPrinter;
import abc.aspectj.ast.AdviceDecl_c;
import abc.aspectj.ast.AdviceSpec;
import abc.aspectj.ast.Pointcut;

public class NamedAdviceDecl_c extends AdviceDecl_c implements NamedAdviceDecl {

	public NamedAdviceDecl_c(Position pos, Identifier ident,
			Flags flags, AdviceSpec spec,
			List throwTypes, Pointcut pc, Block body) {
		super(pos, flags, spec, throwTypes, pc, body);
		this.ident = ident;
	}

	private Identifier ident;
	
	@Override
	public Identifier getIdent() {
		return ident;
	}

    public void prettyPrint(CodeWriter w, PrettyPrinter tr)
    {
        w.begin(0);
        w.write(flags.translate());

        print(spec,w,tr);

        w.begin(0);

        if (! throwTypes().isEmpty()) {
            w.allowBreak(6);
            w.write("throws ");

            for (Iterator i = throwTypes().iterator(); i.hasNext(); ) {
                TypeNode tn = (TypeNode) i.next();
                print(tn, w, tr);
        
                if (i.hasNext()) {
                    w.write(",");
                    w.allowBreak(4, " ");
                }
            }
        }

        w.end();
        
        //------------------ ACRESCENTAMOS:
        w.write(" " + ident.getIdentifier());

        w.write(":");

        w.allowBreak(0);

        print(pc, w, tr);
        
        if (body != null) 
            printSubStmt(body, w, tr);
        else
            w.write(";");

        w.end();
    }
	
}
